#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time     : 2021/6/17 16:20
# @Author   : chengfeng
# @Email    : chengfeng@inhand.com.cn
# @File     : getVariable.py

from Common.publicMethod import PublicMethod
import os

read_yaml = PublicMethod.read_yaml
root_dir = os.path.dirname(__file__)

"""
将yaml文件中的键值以变量名的方式返回
"""


class Variable:

    def __init__(self, dir_name: str, file_name: str):
        self.__path = os.path.join(root_dir, dir_name, file_name)
        self.__content = read_yaml(self.__path)
        self.__elements(self.__content)

    @staticmethod
    def __elements(yaml_: dict):
        for key, value in yaml_.items():
            if type(value) != dict:
                setattr(Variable, key, value)
            else:
                for ink, inv in value.items():
                    newkey = key + '_' + ink
                    setattr(Variable, newkey, inv)
